//
//  ShopInfoTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/4/5.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "ShopInfoTableViewCell.h"

@interface ShopInfoTableViewCell()

@property (nonatomic,strong) UIView *titleView;
@property (nonatomic,strong) UIView *infoView;

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *sellCountLabel;
@property (nonatomic,strong) UILabel *infoLabel;
@property (nonatomic,strong) UITextView *infoTextView;
@end

@implementation ShopInfoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        self.contentView.backgroundColor = getColor(@"f1f2f6");
        self.separatorInset = UIEdgeInsetsZero;
        if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
            self.layoutMargins = UIEdgeInsetsZero;
        }
        
        _titleView = [UIView new];
        _titleView.backgroundColor = [UIColor whiteColor];
        
        _infoView = [UIView new];
        _infoView.backgroundColor = [UIColor whiteColor];
        
        _titleLabel = [UILabel new];
        _titleLabel.font = DEF_FontSize_13;
        
        _sellCountLabel = [UILabel new];
        _sellCountLabel.textAlignment = NSTextAlignmentRight;
        _sellCountLabel.textColor = getColor(redColor);
        _sellCountLabel.font = DEF_FontSize_13;

        _infoLabel = [UILabel new];
        _infoLabel.numberOfLines = 0;
        _infoLabel.font = DEF_FontSize_11;
        
        _infoTextView = [UITextView new];
        _infoTextView.font = DEF_FontSize_13;
        _infoTextView.editable = NO;

        [self.contentView addSubview:_titleView];
        [self.contentView addSubview:_infoView];
        [_titleView addSubview:_titleLabel];
        [_titleView addSubview:_sellCountLabel];
        [_infoView addSubview:_infoLabel];
        [_infoView addSubview:_infoTextView];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _titleView.frame = CGRectMake(0, 5, SCREEN_WIDTH, 27);
    _infoView.frame = CGRectMake(0, 37, SCREEN_WIDTH, self.frame.size.height - 37);
    
    _titleLabel.frame = CGRectMake(10, 0, SCREEN_WIDTH-20, 27);
    _sellCountLabel.frame = CGRectMake(10, 0, SCREEN_WIDTH-20, 27);
    _infoLabel.frame = CGRectMake(10, 5, SCREEN_WIDTH-20, self.frame.size.height - 47);
    _infoTextView.frame = CGRectMake(10, 5, SCREEN_WIDTH-20, self.frame.size.height - 47);
}

- (void)setState:(ShopInfoState)state{
    _state = state;
    _infoTextView.hidden = NO;
    _infoLabel.hidden = NO;

    switch (_state) {
        case ShopInfoState_shopInfo:{
            _titleLabel.text = @"店铺介绍";
            _titleLabel.textColor = [UIColor blackColor];
            _sellCountLabel.hidden = YES;
            
            NSString *temp = [NSString stringWithFormat:@"开店时间  %@\n公司地址  %@\n联系方式  %@",self.model[@"open_time"],self.model[@"s_address"],self.model[@"s_mobile"]];
            NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:temp];
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            [paragraphStyle setLineSpacing:5];//调整行间距
            [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
            _infoLabel.attributedText = attributedString;
            _infoTextView.hidden = YES;
        }break;
        case ShopInfoState_shopAbout:{
            _titleLabel.text = @"店铺简介";
            _titleLabel.textColor = [UIColor blackColor];
            _sellCountLabel.hidden = NO;
            _infoTextView.text = self.model[@"describe"];
            _infoLabel.hidden = YES;

        }break;
//        case ShopInfoState_evaluate:{
//            _titleLabel.text = @"店铺评价";
//            _titleLabel.textColor = [UIColor blackColor];
//            _sellCountLabel.hidden = NO;
//            _infoTextView.text = @"评价评价评价评价评价评价评价评价评价";
//            _infoLabel.hidden = YES;
//            
//        }break;
        default:break;
    }
}


@end
